<?php TPL::output('global/header.tpl.htm'); ?>

<div class="aw-container-wrap">
    <div class="container aw-publish">
        <div class="row">
            <div class="aw-content-wrap clearfix">
                <div class="col-sm-12 col-md-9 aw-main-content">
                    <!-- tab 切换 -->
                    <ul class="nav nav-tabs aw-nav-tabs active">
                        <li class="active"><a href="publish/ticket/"><?php _e('工单'); ?></a></li>
                        <?php if ($this->user_info['permission']['publish_article']) { ?>
                        <li><a href="publish/article/"><?php _e('文章'); ?></a></li>
                        <?php } ?>
                        <li><a href="publish/"><?php _e('问题'); ?></a></li>
                        <h2 class="hidden-xs"><i class="icon icon-ask"></i> <?php _e('发起'); ?></h2>
                    </ul>
                    <!-- end tab 切换 -->
                    <form action="ticket/ajax/publish/" method="post" id="ticket_form" onsubmit="return false;">
                        <input type="hidden" name="post_hash" value="<?php echo new_post_hash(); ?>" />
                        <input type="hidden" name="attach_access_key" value="<?php echo $this->attach_access_key; ?>" />

                        <div class="aw-mod aw-mod-publish">
                            <div class="mod-body">
                                <h3><?php _e('标题'); ?>:</h3>
                                <!-- 问题标题 -->
                                <div class="aw-publish-title active">
                                    <div>
                                        <input type="text" placeholder="<?php _e('标题'); ?>..." name="title" value="" class="form-control" />
                                        <div class="aw-publish-suggest-question hide">
                                            <p class="text-color-999">你的问题可能已经有答案</p>
                                            <ul class="aw-dropdown-list">
                                            </ul>
                                        </div>
                                    </div>
                                </div>
                                <!-- end 问题标题 -->

                                <h3><?php _e('补充说明 (选填)'); ?>:</h3>
                                <div class="aw-mod aw-editor-box">
                                    <div class="mod-head">
                                        <div class="wmd-panel">
                                        <?php  if(get_hook_config('editor')['type']['value']=='ueditor'):?> 
                                        <script id="wmd-input" name="message" type="text/plain"><?php echo html_entity_decode($this->draft_content['message']); ?></script>
                                        <?php  elseif(get_hook_config('editor')['type']['value']=='ckeditor'):?> 
                                        <textarea class="wmd-input form-control autosize editor" id="wmd-input" rows="15" name="message"><?php echo html_entity_decode($this->draft_content['message']); ?></textarea>
                                        <?php else:?>
                                            <textarea style="display: none;" id="wangcontent" rows="15" name="message"><?php echo html_entity_decode($this->draft_content['message']); ?></textarea>
                                            <div id="wmd-input">

                                            </div>
                                        <?php endif;?>

                                        </div>
                                    </div>
                                    <div class="mod-body">
                                        <span class="pull-right text-color-999" id="question_detail_message">&nbsp;</span>

                                    </div>
                                </div>
                                <?php if ($this->human_valid) { ?>
                                <div class="aw-auth-img clearfix">
                                    <div class="embed-captcha  pull-right" style="width: 260px;"></div>
                                    <p class="wait  pull-right">正在加载验证码......</p>
                                    <!-- <input class="form-control pull-right" type="text" name="seccode_verify" placeholder="验证码" />
                                    <em class="auth-img pull-right"><img src="" onclick="this.src = G_BASE_URL + '/account/captcha/' + Math.floor(Math.random() * 10000);" id="captcha"  /></em> -->
                                </div>
                                <?php } ?>
                            </div>
                            <div class="mod-footer clearfix">
                                <a class="btn btn-large btn-success btn-publish-submit" id="publish_submit" <?php if (!$this->human_valid) { ?>onclick="AWS.ajax_post($('#ticket_form')); return false;"<?php } ?>><?php _e('确认发起'); ?></a>
                            </div>
                        </div>
                    </form>
                </div>
                <!-- 侧边栏 -->
                <div class="col-sm-12 col-md-3 aw-side-bar hidden-xs">

                </div>
                <!-- end 侧边栏 -->
            </div>
        </div>
    </div>
</div>
<?php 
hook('editor','init',['name'=>'wmd-input']);
?>
<script type="text/javascript">
    var ATTACH_ACCESS_KEY = '<?php echo $this->attach_access_key; ?>';
    var CATEGORY_ID = <?php echo intval($_POST['category_id']); ?>;
    var PUBLISH_TYPE = 'ticket';
<?php if ($this->human_valid) { ?>
    var handlerEmbed = function (captchaObj) {
        $('#publish_submit').click(function(){
            var validate = captchaObj.getValidate();
            if (!validate) {
                AWS.alert("请先完成验证");
                return false;
            } else{
                AWS.ajax_post($('#ticket_form'), AWS.ajax_processer, 'reply');
                captchaObj.reset(); // 调用该接口进行重置 
                return false;
            }
        });
        // 将验证码加到id为captcha的元素里，同时会有三个input的值：geetest_challenge, geetest_validate, geetest_seccode
        captchaObj.appendTo(".embed-captcha");
        captchaObj.onReady(function () {
            $(".wait").css('display','none');
        });
    };

    $.ajax({
        // 获取id，challenge，success（是否启用failback）
        url: G_BASE_URL+ "/account/slide_captcha/?t=" + (new Date()).getTime()+"&client_type='web'", // 加随机数防止缓存
        type: "get",
        dataType: "json",
        success: function (data) {
            var dataObj = eval('(' + data.rsm + ')');
            // 使用initGeetest接口
            // 参数1：配置参数
            // 参数2：回调，回调的第一个参数验证码对象，之后可以使用它做appendTo之类的事件
            initGeetest({
                gt: dataObj.gt,
                challenge: dataObj.challenge,
                new_captcha: dataObj.new_captcha,
                offline: !dataObj.success, // 表示用户后台检测极验服务器是否宕机，一般不需要关注
                product: "embed", // 产品形式，包括：float，embed，popup。注意只对PC版验证码有效
                width: '100%' // 设置按钮宽度, 与父元素宽度一致
            }, handlerEmbed);
        }
    });
<?php } ?>
</script>

<?php TPL::output('global/footer.tpl.htm'); ?>
